<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ktig extends CI_Model {
	function __construct()
	{
		parent::__construct();
	}
	function db_check() {
		$username = $this->input->post('user_name'); 
		$pass = $this->input->post('password');
		
		$this->db->where('USERNAME', $username);
		$this->db->where('PASSWORD', $pass);
		$query = $this->db->get('user'); 
		return $query->result();
	}
	public function is_logged_in()
	{
		$is_logged_in = $this->session->userdata('is_logged_in');
		$nama=$this->session->userdata('username');
		
		if($is_logged_in != true)
		{
			redirect('welcome');
		}
	}
	function pembul_status($data)
	{
		return $this->db->get_where('laporan_bulanan',array($data.' !='=>' ', 'RTL'.$data.' !='=>2,'JENIS_FORM'=>1,'STATUS_PROGRES'=>1))->row();
	}
	function patrolsub_status($data)
	{
		return $this->db->get_where('laporan_bulanan',array($data.' !='=>' ', 'RTL'.$data.' !='=>2,'JENIS_FORM'=>2,'STATUS_PROGRES'=>1))->row();
	}
	function haspem_status($data)
	{
		//return $this->db->get_where('laporan_bulanan',array($data.' !='=>' ', 'RTL'.$data=>1, 'TB'.$data.' >'=>2))->row();
		return $this->db->get_where('laporan_bulanan',array($data.' !='=>' ', 'RTL'.$data.' !='=>2,'STATUS_PROGRES'=>1))->row();
	}
	function list_kartu_stop()
	{
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('kartu_stop');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_pembul()
	{
		$this->db->where('JENIS_FORM', 1);
		//$query = $this->db->query('select * from laporan_bulanan where JENIS_FORM=1 order by TANGGAL desc ');
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('laporan_bulanan');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_haspem()
	{
		$this->db->where('JENIS_FORM', 3);
		//$query = $this->db->query('select * from laporan_bulanan where JENIS_FORM=1 order by TANGGAL desc ');
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('laporan_bulanan');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_patrolsub()
	{
		$this->db->where('JENIS_FORM', 2);
		//$query = $this->db->query('select * from laporan_bulanan where JENIS_FORM=1 order by TANGGAL desc ');
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('laporan_bulanan');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_safetypatrol()
	{
		$this->db->where('JENIS_FORM', 1);
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('checklist_safety');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_safetypatrolpengawas()
	{
		$this->db->where('JENIS_FORM', 2);
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('checklist_safety');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_insentif()
	{
		$i=0;
		$laporan_bulanan=0;
		$query1 = $this->db->group_by('ANGGOTA')->where('JENIS_FORM', 1)->get('laporan_bulanan');
		foreach ($query1->result() as $data1)
		{
			$laporan_bulanan++;
			$x=$data1->ANGGOTA;
			$datalist[$x]['departemen'] = $data1->DEPARTEMEN;
			$datalist[$x]['anggota'] = $data1->ANGGOTA;
			$datalist[$x]['tanggal'] = $data1->TANGGAL;
			$datalist[$x]['data2'] = "laporan_bulanan";
			$i++;
		}
		
		$checklist_safety=0;
		$query2 = $this->db->group_by('ANGGOTA')->where('JENIS_FORM', 1)->get('checklist_safety');
		foreach ($query2->result() as $data2)
		{
			$x=$data2->ANGGOTA;
			$datalist[$x]['departemen'] = $data2->DEPARTEMEN;
			$datalist[$x]['anggota'] = $data2->ANGGOTA;
			$datalist[$x]['tanggal'] = $data2->TANGGAL;
			$datalist[$x]['data1'] = "checklist_safety";
			$i++;
		}
		
		$checklist_fasilitas=0;
		$query3 = $this->db->group_by('ANGGOTA')->where('JENIS_FORM', 1)->get('checklist_fasilitas');
		foreach ($query3->result() as $data3)
		{
			$x=$data3->ANGGOTA;
			$datalist[$x]['departemen'] = $data3->DEPARTEMEN;
			$datalist[$x]['anggota'] = $data3->ANGGOTA;
			$datalist[$x]['tanggal'] = $data3->TANGGAL;
			$datalist[$x]['data3'] = "checklist_fasilitas";
			$i++;
		}
		
		$kartu_stop=0;
		$query4 = $this->db->group_by('NAMA_PEMEGANG')->get('kartu_stop');
		foreach ($query4->result() as $data4)
		{
			$x=$data4->NAMA_PEMEGANG;
			$datalist[$x]['departemen'] = $data4->DEPARTEMEN;
			$datalist[$x]['anggota'] = $data4->NAMA_PEMEGANG;
			$datalist[$x]['tanggal'] = $data4->TANGGAL;
			$datalist[$x]['data4'] = "kartu_stop";
			$i++;
		}
		if(empty($datalist))
		{
			$data_final=null;
		}
		else
		{
			$data_final=$datalist;
		}
		return $data_final;
    }
	function list_fasilitas()
	{
		$this->db->where('JENIS_FORM', 1);
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('checklist_fasilitas');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_fasilitaspengawas()
	{
		$this->db->where('JENIS_FORM', 2);
		$this->db->order_by('TANGGAL', 'desc');
		$query = $this->db->get('checklist_fasilitas');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function list_usman()
	{
		$this->db->order_by('ID_USER', 'asc');
		$query = $this->db->get('user');
        
		if ($query->num_rows() > 0 )
		{
            foreach ($query->result() as $data)
			{
                $datalist[] = $data;
            }
            return $datalist;
        }
    }
	function data_stop($id)
	{
		return $this->db->get_where('kartu_stop',array('ID_KARTU'=>$id))->row();
	}
	function data_pembul($id)
	{
		return $this->db->get_where('laporan_bulanan',array('ID_LAPORAN'=>$id))->row();
	}
	function data_haspem($id)
	{
		return $this->db->get_where('laporan_bulanan',array('ID_LAPORAN'=>$id))->row();
	}
	function data_patrolsub($id)
	{
		return $this->db->get_where('laporan_bulanan',array('ID_LAPORAN'=>$id))->row();
	}
	function data_fasilitas($id)
	{
		return $this->db->get_where('checklist_fasilitas',array('ID_FASILITAS'=>$id))->row();
	}
	function data_fasilitaspengawas($id)
	{
		return $this->db->get_where('checklist_fasilitas',array('ID_FASILITAS'=>$id))->row();
	}
	function data_safetypatrol($id)
	{
		return $this->db->get_where('checklist_safety',array('ID_FORM'=>$id))->row();
	}
	function data_safetypatrolpengawas($id)
	{
		return $this->db->get_where('checklist_safety',array('ID_FORM'=>$id))->row();
	}
	function data_usman($id)
	{
		return $this->db->get_where('user',array('ID_USER'=>$id))->row();
	}
	function hapus_stop($id)
	{
		$this->db->delete('kartu_stop', array('ID_KARTU' => $id));
	}
	function hapus_pembul($id)
	{
		$this->db->delete('laporan_bulanan', array('ID_LAPORAN' => $id));
	}
	function hapus_haspem($id)
	{
		$this->db->delete('laporan_bulanan', array('ID_LAPORAN' => $id));
	}
	function hapus_patrolsub($id)
	{
		$this->db->delete('laporan_bulanan', array('ID_LAPORAN' => $id));
	}
	function hapus_fasilitas($id)
	{
		$this->db->delete('checklist_fasilitas', array('ID_FASILITAS' => $id));
	}
	function hapus_fasilitaspengawas($id)
	{
		$this->db->delete('checklist_fasilitas', array('ID_FASILITAS' => $id));
	}
	function hapus_safetypatrol($id)
	{
		$this->db->delete('checklist_safety', array('ID_FORM' => $id));
	}
	function hapus_safetypatrolpengawas($id)
	{
		$this->db->delete('checklist_safety', array('ID_FORM' => $id));
	}
	function hapus_usman($id)
	{
		$this->db->delete('user', array('ID_USER' => $id));
	}
	function update_fasilitas($id)
	{
		$tanggal_input = $this->input->post('tanggal');
		$jam_input = $this->input->post('jam');
		
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		$jam = date("H:i:s", strtotime($jam_input));
		
		if($this->input->post('bahan')=="ya") { $bahan=1; } else { $bahan=null; }
		if($this->input->post('put')=="ya") { $put=1; } else { $put=null; }
		if($this->input->post('kun')=="ya") { $kun=1; } else { $kun=null; }
		if($this->input->post('lih')=="ya") { $lih=1; } else { $lih=null; }
		if($this->input->post('tand')=="ya") { $tand=1; } else { $tand=null; }
		if($this->input->post('chy')=="ya") { $chy=1; } else { $chy=null; }
		if($this->input->post('ang')=="ya") { $ang=1; } else { $ang=null; }
		
		if($this->input->post('lok')=="ya") { $lok=1; } else { $lok=null; }
		if($this->input->post('tek')=="ya") { $tek=1; } else { $tek=null; }
		if($this->input->post('seg')=="ya") { $seg=1; } else { $seg=null; }
		if($this->input->post('uli')=="ya") { $uli=1; } else { $uli=null; }
		if($this->input->post('sumb')=="ya") { $sumb=1; } else { $sumb=null; }
		if($this->input->post('tab')=="ya") { $tab=1; } else { $tab=null; }
		
		if($this->input->post('exi')=="ya") { $exi=1; } else { $exi=null; }
		if($this->input->post('hlg')=="ya") { $hlg=1; } else { $hlg=null; }
		if($this->input->post('eva')=="ya") { $eva=1; } else { $eva=null; }
		if($this->input->post('papa')=="ya") { $papa=1; } else { $papa=null; }
		if($this->input->post('ppn')=="ya") { $ppn=1; } else { $ppn=null; }
		if($this->input->post('asm')=="ya") { $asm=1; } else { $asm=null; }
		if($this->input->post('bly')=="ya") { $bly=1; } else { $bly=null; }
		
		if($this->input->post('sft')=="ya") { $sft=1; } else { $sft=null; }
		if($this->input->post('lang')=="ya") { $lang=1; } else { $lang=null; }
		if($this->input->post('shw')=="ya") { $shw=1; } else { $shw=null; }
		
		$data=array(
			'JENIS_FORM'=>1,
			'LOKASI'=>$this->input->post('lokasi'),
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			'K1'=>$bahan,
			'KK1'=>$this->input->post('ket1'),
			'K2'=>$put,
			'KK2'=>$this->input->post('ket2'),
			'K3'=>$kun,
			'KK3'=>$this->input->post('ket3'),
			'K4'=>$lih,
			'KK4'=>$this->input->post('ket4'),
			'K5'=>$tand,
			'KK5'=>$this->input->post('ket5'),
			'K6'=>$chy,
			'KK6'=>$this->input->post('ket6'),
			'K7'=>$ang,
			'KK7'=>$this->input->post('ket7'),
			
			'A1'=>$lok,
			'KA1'=>$this->input->post('ket8'),
			'A2'=>$tek,
			'KA2'=>$this->input->post('ket9'),
			'A3'=>$seg,
			'KA3'=>$this->input->post('ket10'),
			'A4'=>$uli,
			'KA4'=>$this->input->post('ket11'),
			'A5'=>$sumb,
			'KA5'=>$this->input->post('ket12'),
			'A6'=>$tab,
			'KA6'=>$this->input->post('ket13'),
			
			'P1'=>$exi,
			'PK1'=>$this->input->post('ket14'),
			'P2'=>$hlg,
			'PK2'=>$this->input->post('ket15'),
			'P3'=>$eva,
			'PK3'=>$this->input->post('ket16'),
			'P4'=>$papa,
			'PK4'=>$this->input->post('ket17'),
			'P5'=>$ppn,
			'PK5'=>$this->input->post('ket18'),
			'P6'=>$asm,
			'PK6'=>$this->input->post('ket19'),
			'P7'=>$bly,
			'PK7'=>$this->input->post('ket20'),
			
			'E1'=>$sft,
			'PE1'=>$this->input->post('ket21'),
			'E2'=>$lang,
			'PE2'=>$this->input->post('ket22'),
			'E3'=>$shw,
			'PE3'=>$this->input->post('ket23'),
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$this->input->post('skertaris')
		  );
		  
		$this->db->where('ID_FASILITAS',$id);
		$this->db->update('checklist_fasilitas',$data);
	}
	function update_fasilitaspengawas($id)
	{
		$tanggal_input = $this->input->post('tanggal');
		$jam_input = $this->input->post('jam');
		
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		$jam = date("H:i:s", strtotime($jam_input));
		
		if($this->input->post('bahan')=="ya") { $bahan=1; } else { $bahan=null; }
		if($this->input->post('put')=="ya") { $put=1; } else { $put=null; }
		if($this->input->post('kun')=="ya") { $kun=1; } else { $kun=null; }
		if($this->input->post('lih')=="ya") { $lih=1; } else { $lih=null; }
		if($this->input->post('tand')=="ya") { $tand=1; } else { $tand=null; }
		if($this->input->post('chy')=="ya") { $chy=1; } else { $chy=null; }
		if($this->input->post('ang')=="ya") { $ang=1; } else { $ang=null; }
		
		if($this->input->post('lok')=="ya") { $lok=1; } else { $lok=null; }
		if($this->input->post('tek')=="ya") { $tek=1; } else { $tek=null; }
		if($this->input->post('seg')=="ya") { $seg=1; } else { $seg=null; }
		if($this->input->post('uli')=="ya") { $uli=1; } else { $uli=null; }
		if($this->input->post('sumb')=="ya") { $sumb=1; } else { $sumb=null; }
		if($this->input->post('tab')=="ya") { $tab=1; } else { $tab=null; }
		
		if($this->input->post('exi')=="ya") { $exi=1; } else { $exi=null; }
		if($this->input->post('hlg')=="ya") { $hlg=1; } else { $hlg=null; }
		if($this->input->post('eva')=="ya") { $eva=1; } else { $eva=null; }
		if($this->input->post('papa')=="ya") { $papa=1; } else { $papa=null; }
		if($this->input->post('ppn')=="ya") { $ppn=1; } else { $ppn=null; }
		if($this->input->post('asm')=="ya") { $asm=1; } else { $asm=null; }
		if($this->input->post('bly')=="ya") { $bly=1; } else { $bly=null; }
		
		if($this->input->post('sft')=="ya") { $sft=1; } else { $sft=null; }
		if($this->input->post('lang')=="ya") { $lang=1; } else { $lang=null; }
		if($this->input->post('shw')=="ya") { $shw=1; } else { $shw=null; }
		
		$data=array(
			'JENIS_FORM'=>2,
			'LOKASI'=>$this->input->post('lokasi'),
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			'K1'=>$bahan,
			'KK1'=>$this->input->post('ket1'),
			'K2'=>$put,
			'KK2'=>$this->input->post('ket2'),
			'K3'=>$kun,
			'KK3'=>$this->input->post('ket3'),
			'K4'=>$lih,
			'KK4'=>$this->input->post('ket4'),
			'K5'=>$tand,
			'KK5'=>$this->input->post('ket5'),
			'K6'=>$chy,
			'KK6'=>$this->input->post('ket6'),
			'K7'=>$ang,
			'KK7'=>$this->input->post('ket7'),
			
			'A1'=>$lok,
			'KA1'=>$this->input->post('ket8'),
			'A2'=>$tek,
			'KA2'=>$this->input->post('ket9'),
			'A3'=>$seg,
			'KA3'=>$this->input->post('ket10'),
			'A4'=>$uli,
			'KA4'=>$this->input->post('ket11'),
			'A5'=>$sumb,
			'KA5'=>$this->input->post('ket12'),
			'A6'=>$tab,
			'KA6'=>$this->input->post('ket13'),
			
			'P1'=>$exi,
			'PK1'=>$this->input->post('ket14'),
			'P2'=>$hlg,
			'PK2'=>$this->input->post('ket15'),
			'P3'=>$eva,
			'PK3'=>$this->input->post('ket16'),
			'P4'=>$papa,
			'PK4'=>$this->input->post('ket17'),
			'P5'=>$ppn,
			'PK5'=>$this->input->post('ket18'),
			'P6'=>$asm,
			'PK6'=>$this->input->post('ket19'),
			'P7'=>$bly,
			'PK7'=>$this->input->post('ket20'),
			
			'E1'=>$sft,
			'PE1'=>$this->input->post('ket21'),
			'E2'=>$lang,
			'PE2'=>$this->input->post('ket22'),
			'E3'=>$shw,
			'PE3'=>$this->input->post('ket23'),
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'STATUS'=>$this->input->post('skertaris')
		  );
		  
		$this->db->where('ID_FASILITAS',$id);
		$this->db->update('checklist_fasilitas',$data);
	}
	function update_usman($id)
	{
		$data=array(
			'NAMA'=>$this->input->post('nama'),
			'USERNAME'=>$this->input->post('username'),
			'PASSWORD'=>$this->input->post('password'),
			'ROLE'=>$this->input->post('role'),
			'BAGIAN'=>$this->input->post('bagian'),
			'Departemen'=>$this->input->post('departemen'),
			'NIK'=>$this->input->post('nik'),
			'Jabatan'=>$this->input->post('jabatan')
		  );
		  
		$this->db->where('ID_USER',$id);
		$this->db->update('user',$data);
	}
	function update_stop($id)
	{	
		$tanggal_input = $this->input->post('tanggal');
		$jam_input = $this->input->post('jam');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		$jam = date("H:i:s", strtotime($jam_input));
		
		$data=array(
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			'LOKASI'=>$this->input->post('lokasi'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'KONDISI_TINDAKAN'=>$this->input->post('aman'),
			'STATUS_REKOMENDASI'=>$this->input->post('aman2'),
			'DESKRIPSI'=>$this->input->post('desc'),
			'REKOMENDASI'=>$this->input->post('rec'),
			'NAMA_PEMEGANG'=>$this->input->post('nama'),
			'NAMA_PELANGGAR'=>$this->input->post('nama1')
		  );
		  
		$this->db->where('ID_KARTU',$id);
		$this->db->update('kartu_stop',$data);
	}
	function update_haspem($id)
	{
		$tanggal_input = $this->input->post('tanggal_jam');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		$jam = date("H:i:s", strtotime($tanggal_input));
		$date = date("Y-m-d");
		
		if($this->input->post('pengawas')==2) { $pengawas=2; } else { $pengawas=1; }
		
		/*if($this->input->post('pengawas'))
		{
			if($this->input->post('skertaris')==1) { $status_progres=2; }
			else { $status_progres=1; }
		}
		else { $status_progres=0; }*/
		
		$status_progres=$this->input->post('status_progres');
		
		$data=array(
			'JENIS_FORM'=>3,
			
			'S1'=>$this->input->post('sta1'),
			'TBS1'=>null,
			'TLS1'=>$this->input->post('tar1'),
			'RTLS1'=>$this->input->post('rtl0'),
			'KETS1'=>$this->input->post('ket1'),
			'TPS1'=>$date,
			'S2'=>$this->input->post('sta2'),
			'TBS2'=>null,
			'TLS2'=>$this->input->post('tar2'),
			'RTLS2'=>$this->input->post('rtl1'),
			'KETS2'=>$this->input->post('ket2'),
			'TPS2'=>$date,
			'S3'=>$this->input->post('sta3'),
			'TBS3'=>null,
			'TLS3'=>$this->input->post('tar3'),
			'RTLS3'=>$this->input->post('rtl2'),
			'KETS3'=>$this->input->post('ket3'),
			'TPS3'=>$date,
			'S4'=>$this->input->post('sta4'),
			'TBS4'=>null,
			'TLS4'=>$this->input->post('tar4'),
			'RTLS4'=>$this->input->post('rtl3'),
			'KETS4'=>$this->input->post('ket4'),
			'TPS4'=>$date,
			'S5'=>$this->input->post('sta5'),
			'TBS5'=>null,
			'TLS5'=>$this->input->post('tar5'),
			'RTLS5'=>$this->input->post('rtl4'),
			'KETS5'=>$this->input->post('ket5'),
			'TPS5'=>$date,
			
			'K1'=>$this->input->post('kta1'),
			'TBK1'=>null,
			'TLK1'=>$this->input->post('tar6'),
			'RTLK1'=>$this->input->post('rt5'),
			'KETK1'=>$this->input->post('ket6'),
			'TPK1'=>$date,
			'K2'=>$this->input->post('kta2'),
			'TBK2'=>null,
			'TLK2'=>$this->input->post('tar7'),
			'RTLK2'=>$this->input->post('rt6'),
			'KETK2'=>$this->input->post('ket7'),
			'TPK2'=>$date,
			'K3'=>$this->input->post('kta3'),
			'TBK3'=>null,
			'TLK3'=>$this->input->post('tar8'),
			'RTLK3'=>$this->input->post('rt7'),
			'KETK3'=>$this->input->post('ket8'),
			'TPK3'=>$date,
			'K4'=>$this->input->post('kta4'),
			'TBK4'=>null,
			'TLK4'=>$this->input->post('tar9'),
			'RTLK4'=>$this->input->post('rt8'),
			'KETK4'=>$this->input->post('ket9'),
			'TPK4'=>$date,
			'K5'=>$this->input->post('kta5'),
			'TBK5'=>null,
			'TLK5'=>$this->input->post('tar10'),
			'RTLK5'=>$this->input->post('rt9'),
			'KETK5'=>$this->input->post('ket10'),
			'TPK5'=>$date,
			
			'G1'=>$this->input->post('lk1'),
			'TBG1'=>null,
			'TLG1'=>$this->input->post('tar11'),
			'RTLG1'=>$this->input->post('rt11'),
			'KETG1'=>$this->input->post('ket11'),
			'TPG1'=>$date,
			'G2'=>$this->input->post('lk2'),
			'TBG2'=>null,
			'TLG2'=>$this->input->post('tar12'),
			'RTLG2'=>$this->input->post('rt12'),
			'KETG2'=>$this->input->post('ket12'),
			'TPG2'=>$date,
			'G3'=>$this->input->post('lk3'),
			'TBG3'=>null,
			'TLG3'=>$this->input->post('tar13'),
			'RTLG3'=>$this->input->post('rt13'),
			'KETG3'=>$this->input->post('ket13'),
			'TPG3'=>$date,
			'G4'=>$this->input->post('lk4'),
			'TBG4'=>null,
			'TLG4'=>$this->input->post('tar14'),
			'RTLG4'=>$this->input->post('rt14'),
			'KETG4'=>$this->input->post('ket14'),
			'TPG4'=>$date,
			'G5'=>$this->input->post('lk5'),
			'TBG5'=>null,
			'TLG5'=>$this->input->post('tar15'),
			'RTLG5'=>$this->input->post('rt15'),
			'KETG5'=>$this->input->post('ket15'),
			'TPG5'=>$date,
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$this->input->post('skertaris'),
			'STATUS_PROGRES'=>$status_progres
			//'PENGAWAS'=>$pengawas
		  );
		  
		$this->db->where('ID_LAPORAN',$id);
		$this->db->update('laporan_bulanan',$data);
		
		/*********Email Alert**********/
		if($this->input->post('skertaris')==1)
		{
			//$this->load->library('email'); 
			$config = Array(
				'protocol' 		=> 'smtp',
				'smtp_host' 	=> 'ssl://smtp.googlemail.com',
				'smtp_port' 	=> 465,
				'smtp_user' 	=> 'k3teamit@gmail.com',
				'smtp_pass' 	=> 'katiga87',
				'mailtype'  	=> 'html', 
				'smtp_timeout'	=> 30,
				'charset'   	=> 'iso-8859-1'
				);

			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$this->email->from('k3teamit@gmail.com','Allen'); 
			$this->email->to("Igha3.moet@gmail.com");
			$this->email->subject('K3 Alert!'); 
			$this->email->message("Terdapat Potensi Bahaya Tinggi"); 
			$this->email->send();
		}
		/******************************/
	}
	function update_safetypatrolpengawas($id)
	{
		
		$tanggal_input = $this->input->post('tanggal');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		
		$jam_input = $this->input->post('jam');
		$jam = date("H:i:s", strtotime($jam_input));
		
		if($this->input->post('ditempatkan_sesuai_tempatnya')=="ya") { $ditempatkan_sesuai_tempatnya=1; } else if($this->input->post('ditempatkan_sesuai_tempatnya')=="tidak") { $ditempatkan_sesuai_tempatnya=2; } else { $ditempatkan_sesuai_tempatnya=null; }
		if($this->input->post('dipilah_sesuai_sifatnya')=="ya") { $dipilah_sesuai_sifatnya=1; } else if($this->input->post('dipilah_sesuai_sifatnya')=="tidak") { $dipilah_sesuai_sifatnya=2; } else { $dipilah_sesuai_sifatnya=null; }
		if($this->input->post('kemasan')=="ya") { $kemasan=1; } else if($this->input->post('kemasan')=="tidak") { $kemasan=2; } else { $kemasan=null; }
		if($this->input->post('adalabel')=="ya") { $adalabel=1; } else if($this->input->post('adalabel')=="tidak") { $adalabel=2; } else { $adalabel=null; }
		if($this->input->post('tempat')=="ya") { $tempat=1; } else if($this->input->post('tempat')=="tidak") { $tempat=2; } else { $tempat=null; }
		if($this->input->post('msds')=="ya") { $msds=1; } else if($this->input->post('msds')=="tidak") { $msds=2; } else { $msds=null; }
		if($this->input->post('apd')=="ya") { $apd=1; } else if($this->input->post('apd')=="tidak") { $apd=2; } else { $apd=null; }
		if($this->input->post('lhyd')=="ya") { $lhyd=1; } else if($this->input->post('lhyd')=="tidak") { $lhyd=2; } else { $lhyd=null; }
		if($this->input->post('fhyd')=="ya") { $fhyd=1; } else if($this->input->post('fhyd')=="tidak") { $fhyd=2; } else { $fhyd=null; }
		if($this->input->post('alarm')=="ya") { $alarm=1; } else if($this->input->post('alarm')=="tidak") { $alarm=2; } else { $alarm=null; }
		if($this->input->post('air')=="ya") { $air=1; } else if($this->input->post('air')=="tidak") { $air=2; } else { $air=null; }
		
		if($this->input->post('canda')=="ya") { $canda=1; } else if($this->input->post('canda')=="tidak") { $canda=2; } else { $canda=null; }
		if($this->input->post('aman')=="ya") { $aman=1; } else if($this->input->post('aman')=="tidak") { $aman=2; } else { $aman=null; }
		if($this->input->post('apdd')=="ya") { $apdd=1; } else if($this->input->post('apdd')=="tidak") { $apdd=2; } else { $apdd=null; }
		if($this->input->post('sim')=="ya") { $sim=1; } else if($this->input->post('sim')=="tidak") { $sim=2; } else { $sim=null; }
		if($this->input->post('waktu')=="ya") { $waktu=1; } else if($this->input->post('waktu')=="tidak") { $waktu=2; } else { $waktu=null; }
		if($this->input->post('airm')=="ya") { $airm=1; } else if($this->input->post('airm')=="tidak") { $airm=2; } else { $airm=null; }
		
		if($this->input->post('sop')=="ya") { $sop=1; } else if($this->input->post('sop')=="tidak") { $sop=2; } else { $sop=null; }
		if($this->input->post('bhy')=="ya") { $bhy=1; } else if($this->input->post('bhy')=="tidak") { $bhy=2; } else { $bhy=null; }
		if($this->input->post('jsa')=="ya") { $jsa=1; } else if($this->input->post('jsa')=="tidak") { $jsa=2; } else { $jsa=null; }
		
		if($this->input->post('laik')=="ya") { $laik=1; } else if($this->input->post('laik')=="tidak") { $laik=2; } else { $laik=null; }
		if($this->input->post('prl')=="ya") { $prl=1; } else if($this->input->post('prl')=="tidak") { $prl=2; } else { $prl=null; }
		if($this->input->post('kal')=="ya") { $kal=1; } else if($this->input->post('kal')=="tidak") { $kal=2; } else { $kal=null; }
		if($this->input->post('tng')=="ya") { $tng=1; } else if($this->input->post('tng')=="tidak") { $tng=2; } else { $tng=null; }
		if($this->input->post('sak')=="ya") { $sak=1; } else if($this->input->post('sak')=="tidak") { $sak=2; } else { $sak=null; }
		
		if($this->input->post('lad')=="ya") { $lad=1; } else if($this->input->post('lad')=="tidak") { $lad=2; } else { $lad=null; }
		if($this->input->post('ven')=="ya") { $ven=1; } else if($this->input->post('ven')=="tidak") { $ven=2; } else { $ven=null; }
		if($this->input->post('pen')=="ya") { $pen=1; } else if($this->input->post('pen')=="tidak") { $pen=2; } else { $pen=null; }
		if($this->input->post('bis')=="ya") { $bis=1; } else if($this->input->post('bis')=="tidak") { $bis=2; } else { $bis=null; }
		if($this->input->post('pap')=="ya") { $pap=1; } else if($this->input->post('pap')=="tidak") { $pap=2; } else { $pap=null; }
		if($this->input->post('ding')=="ya") { $ding=1; } else if($this->input->post('ding')=="tidak") { $ding=2; } else { $ding=null; }
		if($this->input->post('sih')=="ya") { $sih=1; } else if($this->input->post('ding')=="tidak") { $sih=2; } else { $sih=null; }
		if($this->input->post('ramb')=="ya") { $ramb=1; } else if($this->input->post('ramb')=="tidak") { $ramb=2; } else { $ramb=null; }
		if($this->input->post('hala')=="ya") { $hala=1; } else if($this->input->post('hala')=="tidak") { $hala=2; } else { $hala=null; }
		if($this->input->post('rga')=="ya") { $rga=1; } else if($this->input->post('rga')=="tidak") { $rga=2; } else { $rga=null; }
		if($this->input->post('wc')=="ya") { $wc=1; } else if($this->input->post('wc')=="tidak") { $wc=2; } else { $wc=null; }
		if($this->input->post('dra')=="ya") { $dra=1; } else if($this->input->post('dra')=="tidak") { $dra=2; } else { $dra=null; }
		
		if($this->input->post('pengawas'))
		{
			if($this->input->post('skertaris')==1) { $status_skertaris=3; }
			else { $status_skertaris=2; }
		}
		else { $status_skertaris=1; }
		
		if($this->session->userdata('role')==2 or $this->session->userdata('role')==3)
		{
		$data=array(
			'JENIS_FORM'=>2,
			'LOKASI'=>$this->input->post('lokasi'),
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			
			'B1'=>$ditempatkan_sesuai_tempatnya,
			'KB1'=>$this->input->post('ket1'),
			'B2'=>$dipilah_sesuai_sifatnya,
			'KB2'=>$this->input->post('ket2'),
			'B3'=>$kemasan,
			'KB3'=>$this->input->post('ket3'),
			'B4'=>$adalabel,
			'KB4'=>$this->input->post('ket4'),
			'B5'=>$tempat,
			'KB5'=>$this->input->post('ket5'),
			'B6'=>$msds,
			'KB6'=>$this->input->post('ket6'),
			'B7'=>$apd,
			'KB7'=>$this->input->post('ket7'),
			'B8'=>$lhyd,
			'KB8'=>$this->input->post('ket8'),
			'B9'=>$fhyd,
			'KB9'=>$this->input->post('ket9'),
			'B10'=>$alarm,
			'KB10'=>$this->input->post('ket10'),
			'B11'=>$air,
			'KB11'=>$this->input->post('ket11'),
			
			'M1'=>$canda,
			'KM1'=>$this->input->post('ket12'),
			'M2'=>$aman,
			'KM2'=>$this->input->post('ket13'),
			'M3'=>$apdd,
			'KM3'=>$this->input->post('ket14'),
			'M4'=>$sim,
			'KM4'=>$this->input->post('ket15'),
			'M5'=>$waktu,
			'KM5'=>$this->input->post('ket16'),
			'M6'=>$airm,
			'KM6'=>$this->input->post('ket17'),
			
			'C1'=>$sop,
			'KC1'=>$this->input->post('ket18'),
			'C2'=>$bhy,
			'KC2'=>$this->input->post('ket19'),
			'C3'=>$jsa,
			'KC3'=>$this->input->post('ket20'),
			
			'P1'=>$laik,
			'KP1'=>$this->input->post('ket21'),
			'P2'=>$prl,
			'KP2'=>$this->input->post('ket22'),
			'P3'=>$kal,
			'KP3'=>$this->input->post('ket23'),
			'P4'=>$tng,
			'KP4'=>$this->input->post('ket24'),
			'P5'=>$sak,
			'KP5'=>$this->input->post('ket25'),
			
			'L1'=>$lad,
			'KL1'=>$this->input->post('ket26'),
			'L2'=>$ven,
			'KL2'=>$this->input->post('ket27'),
			'L3'=>$pen,
			'KL3'=>$this->input->post('ket28'),
			'L4'=>$bis,
			'KL4'=>$this->input->post('ket29'),
			'L5'=>$pap,
			'KL5'=>$this->input->post('ket30'),
			'L6'=>$ding,
			'KL6'=>$this->input->post('ket31'),
			'L7'=>$sih,
			'KL7'=>$this->input->post('ket32'),
			'L8'=>$ramb,
			'KL8'=>$this->input->post('ket33'),
			'L9'=>$hala,
			'KL9'=>$this->input->post('ket34'),
			'L10'=>$rga,
			'KL10'=>$this->input->post('ket35'),
			'L11'=>$wc,
			'KL11'=>$this->input->post('ket36'),
			'L12'=>$dra,
			'KL12'=>$this->input->post('ket37'),
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$status_skertaris
		  );
		}
		else
		{
		$data=array(
			'JENIS_FORM'=>2,
			'LOKASI'=>$this->input->post('lokasi'),
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			
			'B1'=>$ditempatkan_sesuai_tempatnya,
			'KB1'=>$this->input->post('ket1'),
			'B2'=>$dipilah_sesuai_sifatnya,
			'KB2'=>$this->input->post('ket2'),
			'B3'=>$kemasan,
			'KB3'=>$this->input->post('ket3'),
			'B4'=>$adalabel,
			'KB4'=>$this->input->post('ket4'),
			'B5'=>$tempat,
			'KB5'=>$this->input->post('ket5'),
			'B6'=>$msds,
			'KB6'=>$this->input->post('ket6'),
			'B7'=>$apd,
			'KB7'=>$this->input->post('ket7'),
			'B8'=>$lhyd,
			'KB8'=>$this->input->post('ket8'),
			'B9'=>$fhyd,
			'KB9'=>$this->input->post('ket9'),
			'B10'=>$alarm,
			'KB10'=>$this->input->post('ket10'),
			'B11'=>$air,
			'KB11'=>$this->input->post('ket11'),
			
			'M1'=>$canda,
			'KM1'=>$this->input->post('ket12'),
			'M2'=>$aman,
			'KM2'=>$this->input->post('ket13'),
			'M3'=>$apdd,
			'KM3'=>$this->input->post('ket14'),
			'M4'=>$sim,
			'KM4'=>$this->input->post('ket15'),
			'M5'=>$waktu,
			'KM5'=>$this->input->post('ket16'),
			'M6'=>$airm,
			'KM6'=>$this->input->post('ket17'),
			
			'C1'=>$sop,
			'KC1'=>$this->input->post('ket18'),
			'C2'=>$bhy,
			'KC2'=>$this->input->post('ket19'),
			'C3'=>$jsa,
			'KC3'=>$this->input->post('ket20'),
			
			'P1'=>$laik,
			'KP1'=>$this->input->post('ket21'),
			'P2'=>$prl,
			'KP2'=>$this->input->post('ket22'),
			'P3'=>$kal,
			'KP3'=>$this->input->post('ket23'),
			'P4'=>$tng,
			'KP4'=>$this->input->post('ket24'),
			'P5'=>$sak,
			'KP5'=>$this->input->post('ket25'),
			
			'L1'=>$lad,
			'KL1'=>$this->input->post('ket26'),
			'L2'=>$ven,
			'KL2'=>$this->input->post('ket27'),
			'L3'=>$pen,
			'KL3'=>$this->input->post('ket28'),
			'L4'=>$bis,
			'KL4'=>$this->input->post('ket29'),
			'L5'=>$pap,
			'KL5'=>$this->input->post('ket30'),
			'L6'=>$ding,
			'KL6'=>$this->input->post('ket31'),
			'L7'=>$sih,
			'KL7'=>$this->input->post('ket32'),
			'L8'=>$ramb,
			'KL8'=>$this->input->post('ket33'),
			'L9'=>$hala,
			'KL9'=>$this->input->post('ket34'),
			'L10'=>$rga,
			'KL10'=>$this->input->post('ket35'),
			'L11'=>$wc,
			'KL11'=>$this->input->post('ket36'),
			'L12'=>$dra,
			'KL12'=>$this->input->post('ket37'),
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$status_skertaris
		  );
		  }
		  
		$this->db->where('ID_FORM',$id);
		$this->db->update('checklist_safety',$data);
	}
	function update_safetypatrol($id)
	{
		
		$tanggal_input = $this->input->post('tanggal');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		
		$jam_input = $this->input->post('jam');
		$jam = date("H:i:s", strtotime($jam_input));
		
		if($this->input->post('ditempatkan_sesuai_tempatnya')=="ya") { $ditempatkan_sesuai_tempatnya=1; } else if($this->input->post('ditempatkan_sesuai_tempatnya')=="tidak") { $ditempatkan_sesuai_tempatnya=2; } else { $ditempatkan_sesuai_tempatnya=null; }
		if($this->input->post('dipilah_sesuai_sifatnya')=="ya") { $dipilah_sesuai_sifatnya=1; } else if($this->input->post('dipilah_sesuai_sifatnya')=="tidak") { $dipilah_sesuai_sifatnya=2; } else { $dipilah_sesuai_sifatnya=null; }
		if($this->input->post('kemasan')=="ya") { $kemasan=1; } else if($this->input->post('kemasan')=="tidak") { $kemasan=2; } else { $kemasan=null; }
		if($this->input->post('adalabel')=="ya") { $adalabel=1; } else if($this->input->post('adalabel')=="tidak") { $adalabel=2; } else { $adalabel=null; }
		if($this->input->post('tempat')=="ya") { $tempat=1; } else if($this->input->post('tempat')=="tidak") { $tempat=2; } else { $tempat=null; }
		if($this->input->post('msds')=="ya") { $msds=1; } else if($this->input->post('msds')=="tidak") { $msds=2; } else { $msds=null; }
		if($this->input->post('apd')=="ya") { $apd=1; } else if($this->input->post('apd')=="tidak") { $apd=2; } else { $apd=null; }
		if($this->input->post('lhyd')=="ya") { $lhyd=1; } else if($this->input->post('lhyd')=="tidak") { $lhyd=2; } else { $lhyd=null; }
		if($this->input->post('fhyd')=="ya") { $fhyd=1; } else if($this->input->post('fhyd')=="tidak") { $fhyd=2; } else { $fhyd=null; }
		if($this->input->post('alarm')=="ya") { $alarm=1; } else if($this->input->post('alarm')=="tidak") { $alarm=2; } else { $alarm=null; }
		if($this->input->post('air')=="ya") { $air=1; } else if($this->input->post('air')=="tidak") { $air=2; } else { $air=null; }
		
		if($this->input->post('canda')=="ya") { $canda=1; } else if($this->input->post('canda')=="tidak") { $canda=2; } else { $canda=null; }
		if($this->input->post('aman')=="ya") { $aman=1; } else if($this->input->post('aman')=="tidak") { $aman=2; } else { $aman=null; }
		if($this->input->post('apdd')=="ya") { $apdd=1; } else if($this->input->post('apdd')=="tidak") { $apdd=2; } else { $apdd=null; }
		if($this->input->post('sim')=="ya") { $sim=1; } else if($this->input->post('sim')=="tidak") { $sim=2; } else { $sim=null; }
		if($this->input->post('waktu')=="ya") { $waktu=1; } else if($this->input->post('waktu')=="tidak") { $waktu=2; } else { $waktu=null; }
		if($this->input->post('airm')=="ya") { $airm=1; } else if($this->input->post('airm')=="tidak") { $airm=2; } else { $airm=null; }
		
		if($this->input->post('sop')=="ya") { $sop=1; } else if($this->input->post('sop')=="tidak") { $sop=2; } else { $sop=null; }
		if($this->input->post('bhy')=="ya") { $bhy=1; } else if($this->input->post('bhy')=="tidak") { $bhy=2; } else { $bhy=null; }
		if($this->input->post('jsa')=="ya") { $jsa=1; } else if($this->input->post('jsa')=="tidak") { $jsa=2; } else { $jsa=null; }
		
		if($this->input->post('laik')=="ya") { $laik=1; } else if($this->input->post('laik')=="tidak") { $laik=2; } else { $laik=null; }
		if($this->input->post('prl')=="ya") { $prl=1; } else if($this->input->post('prl')=="tidak") { $prl=2; } else { $prl=null; }
		if($this->input->post('kal')=="ya") { $kal=1; } else if($this->input->post('kal')=="tidak") { $kal=2; } else { $kal=null; }
		if($this->input->post('tng')=="ya") { $tng=1; } else if($this->input->post('tng')=="tidak") { $tng=2; } else { $tng=null; }
		if($this->input->post('sak')=="ya") { $sak=1; } else if($this->input->post('sak')=="tidak") { $sak=2; } else { $sak=null; }
		
		if($this->input->post('lad')=="ya") { $lad=1; } else if($this->input->post('lad')=="tidak") { $lad=2; } else { $lad=null; }
		if($this->input->post('ven')=="ya") { $ven=1; } else if($this->input->post('ven')=="tidak") { $ven=2; } else { $ven=null; }
		if($this->input->post('pen')=="ya") { $pen=1; } else if($this->input->post('pen')=="tidak") { $pen=2; } else { $pen=null; }
		if($this->input->post('bis')=="ya") { $bis=1; } else if($this->input->post('bis')=="tidak") { $bis=2; } else { $bis=null; }
		if($this->input->post('pap')=="ya") { $pap=1; } else if($this->input->post('pap')=="tidak") { $pap=2; } else { $pap=null; }
		if($this->input->post('ding')=="ya") { $ding=1; } else if($this->input->post('ding')=="tidak") { $ding=2; } else { $ding=null; }
		if($this->input->post('sih')=="ya") { $sih=1; } else if($this->input->post('ding')=="tidak") { $sih=2; } else { $sih=null; }
		if($this->input->post('ramb')=="ya") { $ramb=1; } else if($this->input->post('ramb')=="tidak") { $ramb=2; } else { $ramb=null; }
		if($this->input->post('hala')=="ya") { $hala=1; } else if($this->input->post('hala')=="tidak") { $hala=2; } else { $hala=null; }
		if($this->input->post('rga')=="ya") { $rga=1; } else if($this->input->post('rga')=="tidak") { $rga=2; } else { $rga=null; }
		if($this->input->post('wc')=="ya") { $wc=1; } else if($this->input->post('wc')=="tidak") { $wc=2; } else { $wc=null; }
		if($this->input->post('dra')=="ya") { $dra=1; } else if($this->input->post('dra')=="tidak") { $dra=2; } else { $dra=null; }
		
		if($this->input->post('pengawas'))
		{
			if($this->input->post('skertaris')==1) { $status_skertaris=3; }
			else { $status_skertaris=2; }
		}
		else { $status_skertaris=1; }
		
		if($this->session->userdata('role')==2 or $this->session->userdata('role')==3)
		{
		$data=array(
			'JENIS_FORM'=>1,
			'LOKASI'=>$this->input->post('lokasi'),
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			
			'B1'=>$ditempatkan_sesuai_tempatnya,
			'KB1'=>$this->input->post('ket1'),
			'B2'=>$dipilah_sesuai_sifatnya,
			'KB2'=>$this->input->post('ket2'),
			'B3'=>$kemasan,
			'KB3'=>$this->input->post('ket3'),
			'B4'=>$adalabel,
			'KB4'=>$this->input->post('ket4'),
			'B5'=>$tempat,
			'KB5'=>$this->input->post('ket5'),
			'B6'=>$msds,
			'KB6'=>$this->input->post('ket6'),
			'B7'=>$apd,
			'KB7'=>$this->input->post('ket7'),
			'B8'=>$lhyd,
			'KB8'=>$this->input->post('ket8'),
			'B9'=>$fhyd,
			'KB9'=>$this->input->post('ket9'),
			'B10'=>$alarm,
			'KB10'=>$this->input->post('ket10'),
			'B11'=>$air,
			'KB11'=>$this->input->post('ket11'),
			
			'M1'=>$canda,
			'KM1'=>$this->input->post('ket12'),
			'M2'=>$aman,
			'KM2'=>$this->input->post('ket13'),
			'M3'=>$apdd,
			'KM3'=>$this->input->post('ket14'),
			'M4'=>$sim,
			'KM4'=>$this->input->post('ket15'),
			'M5'=>$waktu,
			'KM5'=>$this->input->post('ket16'),
			'M6'=>$airm,
			'KM6'=>$this->input->post('ket17'),
			
			'C1'=>$sop,
			'KC1'=>$this->input->post('ket18'),
			'C2'=>$bhy,
			'KC2'=>$this->input->post('ket19'),
			'C3'=>$jsa,
			'KC3'=>$this->input->post('ket20'),
			
			'P1'=>$laik,
			'KP1'=>$this->input->post('ket21'),
			'P2'=>$prl,
			'KP2'=>$this->input->post('ket22'),
			'P3'=>$kal,
			'KP3'=>$this->input->post('ket23'),
			'P4'=>$tng,
			'KP4'=>$this->input->post('ket24'),
			'P5'=>$sak,
			'KP5'=>$this->input->post('ket25'),
			
			'L1'=>$lad,
			'KL1'=>$this->input->post('ket26'),
			'L2'=>$ven,
			'KL2'=>$this->input->post('ket27'),
			'L3'=>$pen,
			'KL3'=>$this->input->post('ket28'),
			'L4'=>$bis,
			'KL4'=>$this->input->post('ket29'),
			'L5'=>$pap,
			'KL5'=>$this->input->post('ket30'),
			'L6'=>$ding,
			'KL6'=>$this->input->post('ket31'),
			'L7'=>$sih,
			'KL7'=>$this->input->post('ket32'),
			'L8'=>$ramb,
			'KL8'=>$this->input->post('ket33'),
			'L9'=>$hala,
			'KL9'=>$this->input->post('ket34'),
			'L10'=>$rga,
			'KL10'=>$this->input->post('ket35'),
			'L11'=>$wc,
			'KL11'=>$this->input->post('ket36'),
			'L12'=>$dra,
			'KL12'=>$this->input->post('ket37'),
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$status_skertaris
		  );
		}
		else
		{
		$data=array(
			'JENIS_FORM'=>1,
			'LOKASI'=>$this->input->post('lokasi'),
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			
			'B1'=>$ditempatkan_sesuai_tempatnya,
			'KB1'=>$this->input->post('ket1'),
			'B2'=>$dipilah_sesuai_sifatnya,
			'KB2'=>$this->input->post('ket2'),
			'B3'=>$kemasan,
			'KB3'=>$this->input->post('ket3'),
			'B4'=>$adalabel,
			'KB4'=>$this->input->post('ket4'),
			'B5'=>$tempat,
			'KB5'=>$this->input->post('ket5'),
			'B6'=>$msds,
			'KB6'=>$this->input->post('ket6'),
			'B7'=>$apd,
			'KB7'=>$this->input->post('ket7'),
			'B8'=>$lhyd,
			'KB8'=>$this->input->post('ket8'),
			'B9'=>$fhyd,
			'KB9'=>$this->input->post('ket9'),
			'B10'=>$alarm,
			'KB10'=>$this->input->post('ket10'),
			'B11'=>$air,
			'KB11'=>$this->input->post('ket11'),
			
			'M1'=>$canda,
			'KM1'=>$this->input->post('ket12'),
			'M2'=>$aman,
			'KM2'=>$this->input->post('ket13'),
			'M3'=>$apdd,
			'KM3'=>$this->input->post('ket14'),
			'M4'=>$sim,
			'KM4'=>$this->input->post('ket15'),
			'M5'=>$waktu,
			'KM5'=>$this->input->post('ket16'),
			'M6'=>$airm,
			'KM6'=>$this->input->post('ket17'),
			
			'C1'=>$sop,
			'KC1'=>$this->input->post('ket18'),
			'C2'=>$bhy,
			'KC2'=>$this->input->post('ket19'),
			'C3'=>$jsa,
			'KC3'=>$this->input->post('ket20'),
			
			'P1'=>$laik,
			'KP1'=>$this->input->post('ket21'),
			'P2'=>$prl,
			'KP2'=>$this->input->post('ket22'),
			'P3'=>$kal,
			'KP3'=>$this->input->post('ket23'),
			'P4'=>$tng,
			'KP4'=>$this->input->post('ket24'),
			'P5'=>$sak,
			'KP5'=>$this->input->post('ket25'),
			
			'L1'=>$lad,
			'KL1'=>$this->input->post('ket26'),
			'L2'=>$ven,
			'KL2'=>$this->input->post('ket27'),
			'L3'=>$pen,
			'KL3'=>$this->input->post('ket28'),
			'L4'=>$bis,
			'KL4'=>$this->input->post('ket29'),
			'L5'=>$pap,
			'KL5'=>$this->input->post('ket30'),
			'L6'=>$ding,
			'KL6'=>$this->input->post('ket31'),
			'L7'=>$sih,
			'KL7'=>$this->input->post('ket32'),
			'L8'=>$ramb,
			'KL8'=>$this->input->post('ket33'),
			'L9'=>$hala,
			'KL9'=>$this->input->post('ket34'),
			'L10'=>$rga,
			'KL10'=>$this->input->post('ket35'),
			'L11'=>$wc,
			'KL11'=>$this->input->post('ket36'),
			'L12'=>$dra,
			'KL12'=>$this->input->post('ket37'),
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$status_skertaris
		  );
		  }
		$this->db->where('ID_FORM',$id);
		$this->db->update('checklist_safety',$data);
	}
	function update_pembul($id)
	{
		$tanggal_input = $this->input->post('tanggal');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		//$date = date("Y-m-d");
		$date = null;
		
		/*if($this->input->post('pengawas'))
		{
			if($this->input->post('skertaris')==1) { $status_progres=2; }
			else { $status_progres=1; }
		}
		else { $status_progres=0; }*/
		
		$status_progres=$this->input->post('status_progres');
		
		$data=array(
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			//'JAM'=>$jam,
			
			'S1'=>$this->input->post('sta1'),
			'TBS1'=>$this->input->post('tbk1'),
			'TLS1'=>$this->input->post('tar1'),
			'RTLS1'=>$this->input->post('s1'),
			'TPS1'=>$date,
			'S2'=>$this->input->post('sta2'),
			'TBS2'=>$this->input->post('tbk2'),
			'TLS2'=>$this->input->post('tar2'),
			'RTLS2'=>$this->input->post('s2'),
			'TPS2'=>$date,
			'S3'=>$this->input->post('sta3'),
			'TBS3'=>$this->input->post('tbk3'),
			'TLS3'=>$this->input->post('tar3'),
			'RTLS3'=>$this->input->post('s3'),
			'TPS3'=>$date,
			'S4'=>$this->input->post('sta4'),
			'TBS4'=>$this->input->post('tbk4'),
			'TLS4'=>$this->input->post('tar4'),
			'RTLS4'=>$this->input->post('s4'),
			'TPS4'=>$date,
			'S5'=>$this->input->post('sta5'),
			'TBS5'=>$this->input->post('tbk5'),
			'TLS5'=>$this->input->post('tar5'),
			'RTLS5'=>$this->input->post('s5'),
			'TPS5'=>$date,
			
			'K1'=>$this->input->post('kta1'),
			'TBK1'=>$this->input->post('rt6'),
			'TLK1'=>$this->input->post('tar6'),
			'RTLK1'=>$this->input->post('k1'),
			'TPK1'=>$date,
			'K2'=>$this->input->post('kta2'),
			'TBK2'=>$this->input->post('rt7'),
			'TLK2'=>$this->input->post('tar7'),
			'RTLK2'=>$this->input->post('k2'),
			'TPK2'=>$date,
			'K3'=>$this->input->post('kta3'),
			'TBK3'=>$this->input->post('rt8'),
			'TLK3'=>$this->input->post('tar8'),
			'RTLK3'=>$this->input->post('k3'),
			'TPK3'=>$date,
			'K4'=>$this->input->post('kta4'),
			'TBK4'=>$this->input->post('rt9'),
			'TLK4'=>$this->input->post('tar9'),
			'RTLK4'=>$this->input->post('k4'),
			'TPK4'=>$date,
			'K5'=>$this->input->post('kta5'),
			'TBK5'=>$this->input->post('rt10'),
			'TLK5'=>$this->input->post('tar10'),
			'RTLK5'=>$this->input->post('k5'),
			'TPK5'=>$date,
			
			'G1'=>$this->input->post('lk1'),
			'TBG1'=>$this->input->post('rt11'),
			'TLG1'=>$this->input->post('tar11'),
			'RTLG1'=>$this->input->post('l1'),
			'TPG1'=>$date,
			'G2'=>$this->input->post('lk2'),
			'TBG2'=>$this->input->post('rt12'),
			'TLG2'=>$this->input->post('tar12'),
			'RTLG2'=>$this->input->post('l2'),
			'TPG2'=>$date,
			'G3'=>$this->input->post('lk3'),
			'TBG3'=>$this->input->post('rt13'),
			'TLG3'=>$this->input->post('tar13'),
			'RTLG3'=>$this->input->post('l3'),
			'TPG3'=>$date,
			'G4'=>$this->input->post('lk4'),
			'TBG4'=>$this->input->post('rt14'),
			'TLG4'=>$this->input->post('tar14'),
			'RTLG4'=>$this->input->post('l4'),
			'TPG4'=>$date,
			'G5'=>$this->input->post('lk5'),
			'TBG5'=>$this->input->post('rt15'),
			'TLG5'=>$this->input->post('tar15'),
			'RTLG5'=>$this->input->post('l5'),
			'TPG5'=>$date,
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$this->input->post('skertaris'),
			'STATUS_PROGRES'=>$status_progres
		  );
		  
		$this->db->where('ID_LAPORAN',$id);
		$this->db->update('laporan_bulanan',$data);
	}
	function update_patrolsub($id)
	{
		$tanggal_input = $this->input->post('tanggal');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		//$date = date("Y-m-d");
		$date = null;
		
		/*if($this->input->post('pengawas'))
		{
			if($this->input->post('skertaris')==1) { $status_progres=2; }
			else { $status_progres=1; }
		}
		else { $status_progres=0; }*/
		
		$status_progres=$this->input->post('status_progres');
		
		$data=array(
			'BAGIAN'=>$this->input->post('bagian'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'TANGGAL'=>$tanggal,
			//'JAM'=>$jam,
			
			'S1'=>$this->input->post('sta1'),
			'TBS1'=>$this->input->post('tbk1'),
			'TLS1'=>$this->input->post('tar1'),
			'RTLS1'=>$this->input->post('s1'),
			'TPS1'=>$date,
			'S2'=>$this->input->post('sta2'),
			'TBS2'=>$this->input->post('tbk2'),
			'TLS2'=>$this->input->post('tar2'),
			'RTLS2'=>$this->input->post('s2'),
			'TPS2'=>$date,
			'S3'=>$this->input->post('sta3'),
			'TBS3'=>$this->input->post('tbk3'),
			'TLS3'=>$this->input->post('tar3'),
			'RTLS3'=>$this->input->post('s3'),
			'TPS3'=>$date,
			'S4'=>$this->input->post('sta4'),
			'TBS4'=>$this->input->post('tbk4'),
			'TLS4'=>$this->input->post('tar4'),
			'RTLS4'=>$this->input->post('s4'),
			'TPS4'=>$date,
			'S5'=>$this->input->post('sta5'),
			'TBS5'=>$this->input->post('tbk5'),
			'TLS5'=>$this->input->post('tar5'),
			'RTLS5'=>$this->input->post('s5'),
			'TPS5'=>$date,
			
			'K1'=>$this->input->post('kta1'),
			'TBK1'=>$this->input->post('rt6'),
			'TLK1'=>$this->input->post('tar6'),
			'RTLK1'=>$this->input->post('k1'),
			'TPK1'=>$date,
			'K2'=>$this->input->post('kta2'),
			'TBK2'=>$this->input->post('rt7'),
			'TLK2'=>$this->input->post('tar7'),
			'RTLK2'=>$this->input->post('k2'),
			'TPK2'=>$date,
			'K3'=>$this->input->post('kta3'),
			'TBK3'=>$this->input->post('rt8'),
			'TLK3'=>$this->input->post('tar8'),
			'RTLK3'=>$this->input->post('k3'),
			'TPK3'=>$date,
			'K4'=>$this->input->post('kta4'),
			'TBK4'=>$this->input->post('rt9'),
			'TLK4'=>$this->input->post('tar9'),
			'RTLK4'=>$this->input->post('k4'),
			'TPK4'=>$date,
			'K5'=>$this->input->post('kta5'),
			'TBK5'=>$this->input->post('rt10'),
			'TLK5'=>$this->input->post('tar10'),
			'RTLK5'=>$this->input->post('k5'),
			'TPK5'=>$date,
			
			'G1'=>$this->input->post('lk1'),
			'TBG1'=>$this->input->post('rt11'),
			'TLG1'=>$this->input->post('tar11'),
			'RTLG1'=>$this->input->post('l1'),
			'TPG1'=>$date,
			'G2'=>$this->input->post('lk2'),
			'TBG2'=>$this->input->post('rt12'),
			'TLG2'=>$this->input->post('tar12'),
			'RTLG2'=>$this->input->post('l2'),
			'TPG2'=>$date,
			'G3'=>$this->input->post('lk3'),
			'TBG3'=>$this->input->post('rt13'),
			'TLG3'=>$this->input->post('tar13'),
			'RTLG3'=>$this->input->post('l3'),
			'TPG3'=>$date,
			'G4'=>$this->input->post('lk4'),
			'TBG4'=>$this->input->post('rt14'),
			'TLG4'=>$this->input->post('tar14'),
			'RTLG4'=>$this->input->post('l4'),
			'TPG4'=>$date,
			'G5'=>$this->input->post('lk5'),
			'TBG5'=>$this->input->post('rt15'),
			'TLG5'=>$this->input->post('tar15'),
			'RTLG5'=>$this->input->post('l5'),
			'TPG5'=>$date,
			
			'ANGGOTA'=>$this->input->post('nama1'),
			'ANGGOTA2'=>$this->input->post('nama2'),
			'PENGAWAS'=>$this->input->post('pengawas'),
			'STATUS'=>$this->input->post('skertaris'),
			'STATUS_PROGRES'=>$status_progres
		  );
		  
		$this->db->where('ID_LAPORAN',$id);
		$this->db->update('laporan_bulanan',$data);
	}
}
?>